package com.ruoyi.mes.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.domain.ProStock;
import com.ruoyi.mes.vo.product.ProStockInhouVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.FinishInhou;
import com.ruoyi.mes.service.IFinishInhouService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 完工入库Controller
 *
 * @author LongAndHao
 * @date 2023-05-17
 */
@RestController
@RequestMapping("/mes/finishinhou")
public class FinishInhouController extends BaseController
{
    @Autowired
    private IFinishInhouService finishInhouService;

    /**
     * 查询完工入库列表
     */
    @PreAuthorize("@ss.hasPermi('mes:finishinhou:list')")
    @GetMapping("/list")
    public TableDataInfo list(FinishInhou finishInhou)
    {
        startPage();
        List<FinishInhou> list = finishInhouService.selectFinishInhouList(finishInhou);
        return getDataTable(list);
    }

    /**
     * 导出完工入库列表
     */
    @PreAuthorize("@ss.hasPermi('mes:finishinhou:export')")
    @Log(title = "完工入库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinishInhou finishInhou)
    {
        List<FinishInhou> list = finishInhouService.selectFinishInhouList(finishInhou);
        ExcelUtil<FinishInhou> util = new ExcelUtil<FinishInhou>(FinishInhou.class);
        util.exportExcel(response, list, "完工入库数据");
    }

    /**
     * 获取完工入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:finishinhou:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(finishInhouService.selectFinishInhouById(id));
    }

    /**
     * 新增完工入库
     */
    @PreAuthorize("@ss.hasPermi('mes:finishinhou:add')")
    @Log(title = "完工入库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinishInhou finishInhou)
    {
        return toAjax(finishInhouService.insertFinishInhou(finishInhou));
    }

    /**
     * 修改完工入库
     */
    @PreAuthorize("@ss.hasPermi('mes:finishinhou:edit')")
    @Log(title = "完工入库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinishInhou finishInhou)
    {
        return toAjax(finishInhouService.updateFinishInhou(finishInhou));
    }

    /**
     * 删除完工入库
     */
    @PreAuthorize("@ss.hasPermi('mes:finishinhou:remove')")
    @Log(title = "完工入库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(finishInhouService.deleteFinishInhouByIds(ids));
    }

    //*********************

    /**
     * 入库
     * @param proStockInhouVo
     * @return
     */
    @PostMapping("/inHou")
    public AjaxResult inHou(@RequestBody ProStockInhouVo proStockInhouVo){
        return finishInhouService.inHou(proStockInhouVo);
    }

    /**
     * 质检
     * @param id 完工入库id
     * @return
     */
    @PostMapping("/qualityInspection")
    public AjaxResult qualityInspection(@RequestParam Long id) throws IOException {
        return finishInhouService.qualityInspection(id);
    }
}
